package CCRMClient.GUI;

import javax.swing.JPanel;

import java.awt.CardLayout;
import java.awt.Color;

import javax.swing.border.LineBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JButton;

import CCRMClient.ClientStart;
import Common.SERVER_COMMANDS;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;

/**
 * This class implements the template management screen panel, reachable to Marketing Man
 * @author AL
 *
 */
public class TemplateManagementScreen extends JPanel 
{
	
	private JLabel lblTempManagment;
	private JButton btnAddTemp;
	private JButton btnSearchTemp;
	private JButton btnBack;
	

	/**
	 * Create the panel.
	 *
	 */
	public TemplateManagementScreen() 
	{
		
		initialize();
	}
	
	private void initialize() 
	{
		setSize(451, 328);
		setBorder(new LineBorder(new Color(0, 0, 0)));
		setBackground(Color.WHITE);
		setLayout(null);
		add(getLblTempManagment());
		add(getBtnAddTemp());
		add(getBtnSearchTemp());
		add(getBtnBack());
	}

	JLabel getLblTempManagment() 
	{
		if (lblTempManagment == null) 
		{
			lblTempManagment = new JLabel("Marketing Template Management");
			lblTempManagment.setHorizontalAlignment(SwingConstants.CENTER);
			lblTempManagment.setForeground(Color.RED);
			lblTempManagment.setFont(new Font("David", Font.BOLD, 26));
			lblTempManagment.setBackground(Color.WHITE);
			lblTempManagment.setBounds(0, 0, 450, 49);
		}
		return lblTempManagment;
	}

	JButton getBtnAddTemp()
	{
		if (btnAddTemp == null) 
		{
			btnAddTemp = new JButton("Add Template");
			btnAddTemp.addActionListener(new BtnAddTemplateActionListener());
			btnAddTemp.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnAddTemp.setBounds(120, 72, 207, 42);
		}
		return btnAddTemp;
	}
	
	JButton getBtnSearchTemp()
	{
		if (btnSearchTemp == null) 
		{
			btnSearchTemp = new JButton("Search Template");
			btnSearchTemp.addActionListener(new BtnSearchTemplateActionListener());
			btnSearchTemp.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnSearchTemp.setBounds(120, 137, 207, 42);
		}
		return btnSearchTemp;
	}

	
	JButton getBtnBack() {
		if (btnBack == null) {
			btnBack = new JButton("Back");
			btnBack.addActionListener(new BtnQuitActionListener());
			btnBack.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnBack.setBounds(164, 252, 124, 23);
		}
		return btnBack;
	}
	/**
	 * This inner class implements event listener for pressing Back button
	 * @author AL
	 *
	 */
	private class BtnQuitActionListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			ClientStart.panelSwicher(new MarketingScreen());
		}
	}
	/**
	 * This inner class implements event listener for pressing "Add Template" button
	 * @author AL
	 *
	 */
	private class BtnAddTemplateActionListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			if ((!ClientStart.user.getPosition().equals("Marketing Manager")) && (!ClientStart.user.getPosition().equals("Marketing Man")))
				JOptionPane.showMessageDialog(null, "You are not authorized to do this action!", "Security Issue", JOptionPane.ERROR_MESSAGE);
			else {
				TemplateAddScreen addTempScreen = new TemplateAddScreen();
				ClientStart.panelSwicher(addTempScreen);
			}
		}
	}

	/**
	 * This inner class implements event listener for pressing "Search Template" button
	 * @author AL
	 *
	 */
	private class BtnSearchTemplateActionListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			if ((!ClientStart.user.getPosition().equals("Marketing Manager")) && (!ClientStart.user.getPosition().equals("Marketing Man")))
				JOptionPane.showMessageDialog(null, "You are not authorized to do this action!", "Security Issue", JOptionPane.ERROR_MESSAGE);
			else {
				TemplateSearchScreen SearchTempScreen = new TemplateSearchScreen();
				ClientStart.panelSwicher(SearchTempScreen);
			}
		}
	}

}
